package com.jndv.phoneconfig;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.text.format.Formatter;
import android.util.Log;

import java.net.InetAddress;

public class PhoneUtils {

    /**
     * 获取热点的ip
     * @param context
     * @return
     */
    public static String getServerIP(Context context) {
        WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        DhcpInfo dhcp = manager.getDhcpInfo();
        final String address = Formatter.formatIpAddress(dhcp.gateway);// gateway -
        InetAddress serverIP = null;
        try {
            serverIP  = InetAddress.getByName(address);


        } catch (Exception e) {
        }

        return serverIP.getHostAddress() ;
    }
}

